package com.qingkai.onlineshop.presentation.detail

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.qingkai.onlineshop.R
import com.qingkai.onlineshop.ui.theme.OnLineShopAppTheme

/**
 *作者：created by 89270 on 2025/6/16 18:16
 *描述：
 */
@Composable
fun BoxScope.DetailBottomBar(total: Double = 135.0, onClick: () -> Unit = {}) {
    Row(
        modifier = Modifier
            .navigationBarsPadding()
            .align(Alignment.BottomCenter)
            .padding(horizontal = 16.dp)
            .fillMaxWidth()
            .clip(CircleShape)
            .shadow(6.dp)
            .background(MaterialTheme.colorScheme.surfaceContainer),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Text(
            text = "$${total}", modifier = Modifier.weight(1f),
            textAlign = TextAlign.Center, fontWeight = FontWeight.Bold
        )
        FilledTonalButton(onClick = onClick, modifier = Modifier.weight(1.5f)) {
            Image(
                painter = painterResource(id = R.drawable.btn_3),
                contentDescription = "cart",
                modifier = Modifier
                    .size(24.dp)
                    .padding(end = 8.dp)
            )
            Text(text = stringResource(id = R.string.str_add_to_cart))
        }
    }
}

@Preview(showBackground = true)
@Composable
fun DetailBottomBarPreview() {
    OnLineShopAppTheme {
        Box {
            DetailBottomBar()
        }
    }
}

